#include "line.hpp"
#include <cmath>

using namespace BWAPI;
using namespace std;

Line::Line()
:	m_center(Position(0,0)),
	m_direction(0),
	m_length(0)
{
}

void Line::set(
	const BWAPI::Position center,
	const double direction,
	const int length
)
{
	m_center = center;
	m_direction = direction;
	m_length = length;
}

void Line::draw(
	const BWAPI::Color &col
) const
{
	if (m_length==0) {
		return;
	}
	Position p1, p2;
	endPoints(p1, p2);
	Broodwar->drawLineMap(p1.x(), p1.y(), p2.x(), p2.y(), col);
}

Line Line::createParallelLine(
	const int distance
) const
{
	return Line(m_center+Position(distance*cos(m_direction),distance*sin(m_direction)), m_direction, m_length);
}
void Line::endPoints(
	BWAPI::Position &p1,
	BWAPI::Position &p2
) const
{
	p1 = m_center + Position( int(0.5*double(m_length)*cos(m_direction+3.14/2.0)) , int(0.5*double(m_length)*sin(m_direction+3.14/2.0)) );
	p2 = m_center + Position( int(0.5*double(m_length)*cos(m_direction+3.0*3.14/2.0)) , int(0.5*double(m_length)*sin(m_direction+3*3.14/2.0)) );
}
